package com.example.yimai.controller;


import com.example.yimai.entity.FavoriteCollect;
import com.example.yimai.entity.FavoriteItem;
import com.example.yimai.service.impl.FavoriteService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/favorite")
public class FavoriteController {

    @Autowired
    private FavoriteService favoriteService;


    @RequestMapping("/addToCollect")
    public String addToCollect(@RequestAttribute("userId") String userId,
                               @RequestParam String productId,
                               @RequestParam String collectId) {
        return favoriteService.addToCollect(userId, productId, collectId);
    }

    @RequestMapping("/getCollectItems")
    public List<FavoriteItem> getCollectItems(@RequestAttribute("userId") String userId,@RequestParam String collectId){
        return favoriteService.getCollectItems(userId, collectId);
    }

    @RequestMapping("/getCollects")
    public List<FavoriteCollect> getCollects(@RequestAttribute("userId") String userId){
        return favoriteService.getCollects(userId);
    }

    @RequestMapping("/removeFromCollect")
    public String removeFromCollect(@RequestAttribute("userId") String userId,
                                    @RequestParam String productId,
                                    @RequestParam String collectId) {
        return favoriteService.removeFromCollect(userId, productId, collectId);
    }

    @RequestMapping("/createCollect")
    public String createCollect(@RequestAttribute("userId") String userId,@RequestParam String name) {
        return favoriteService.createCollect(userId, name);
    }

    @RequestMapping("/removeCollect")
    public String removeCollect(@RequestAttribute("userId") String userId,@RequestParam String collectId) {
        return favoriteService.removeCollect(userId, collectId);
    }

}
